﻿using System;
using System.Text;
using System.Web.UI;

namespace RDIFramework.WebApp.Modules
{
    public partial class StaffAdmin : BasePage
    {
        protected string organizeJSON = string.Empty;

        /// <summary>
        /// 添加员工权限
        /// </summary>
        private bool permissionAdd = false;

        /// <summary>
        /// 编辑员工权限
        /// </summary>
        private bool permissionEdit = false;

        /// <summary>
        /// 移动员工权限
        /// </summary>
        private bool permissionMoveTo = false;

        /// <summary>
        /// 导出员工数据权限
        /// </summary>
        private bool permissionExport = false;

        /// <summary>
        /// 删除员工权限
        /// </summary>
        private bool permissionDelete = false;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.GetPermission();                
            }
        }       

        //<a id="a_role" href="#" plain="true" class="easyui-linkbutton" icon="icon-add" title="添加员工">添加</a>
        //<a id="a_editpass" href="#" plain="true" class="easyui-linkbutton" icon="icon-edit" title="修改员工">修改</a>
        //<a id="a_boss" href="#" plain="true" class="easyui-linkbutton" icon="icon-delete3" title="删除员工">删除</a>
        //<a id="a_state" href="#" plain="true" class="easyui-linkbutton" icon="icon-arrow_nsew" title="移动员工">移动</a>
        //<a id="a1" href="#" plain="true" class="easyui-linkbutton" icon="icon-export" title="导出员工数据">导出</a>

        /// <summary>
        /// 获得权限
        /// </summary>
        private void GetPermission()
        {
            this.permissionAdd      = this.IsAuthorized("StaffAdmin.Add");
            this.permissionEdit     = this.IsAuthorized("StaffAdmin.Edit");
            this.permissionMoveTo   = this.IsAuthorized("StaffAdmin.Move");
            this.permissionDelete   = this.IsAuthorized("StaffAdmin.Delete");
            this.permissionExport   = this.IsAuthorized("StaffAdmin.Export");           
        }

        /// <summary>
        /// 加载工具栏
        /// </summary>
        /// <returns>工具栏HTML</returns>
        public override string BuildToolBarButtons()
        {
            StringBuilder sb = new StringBuilder();
            string linkbtn_template = "<a id=\"btn{0}\" class=\"easyui-linkbutton\" style=\"float:left\"  plain=\"true\" href=\"javascript:;\" icon=\"{1}\"  {2} title=\"{3}\">{4}</a>";
            sb.Append("<a id=\"btnRefresh\" class=\"easyui-linkbutton\" style=\"float:left\"  plain=\"true\" href=\"javascript:;\" icon=\"icon-reload\"  title=\"重新加载\">刷新</a> ");
            sb.Append("<div class='datagrid-btn-separator'></div> ");
            sb.Append(string.Format(linkbtn_template, "AddStaff", "icon-vcard_add", permissionAdd ? "" : "disabled=\"True\"", "添加员工", "添加"));
            sb.Append(string.Format(linkbtn_template, "EditStaff", "icon-vcard_edit", permissionEdit ? "" : "disabled=\"True\"", "修改员工", "修改"));
            sb.Append(string.Format(linkbtn_template, "DeleteStaff", "icon-vcard_delete", permissionDelete ? "" : "disabled=\"True\"", "删除员工", "删除"));
            sb.Append("<div class='datagrid-btn-separator'></div> ");
            sb.Append(string.Format(linkbtn_template, "MoveTo", "icon-arrow_nsew", permissionMoveTo ? "" : "disabled=\"True\"", "移动选中的员工", "移动"));
            sb.Append("<div class='datagrid-btn-separator'></div> ");
            sb.Append(string.Format(linkbtn_template, "Export", "icon-export", permissionExport ? "" : "disabled=\"True\"", "导出员工数据", "导出"));

            return sb.ToString();
        }
    }
}